import React, { Component } from "react";
import { Menu, Row, Col } from "antd";
import { Link, withRouter } from "react-router-dom";
import IndexList from "./list";



class Index extends Component {
	constructor(props) {
		super(props);
		this.state = {
			now: this._getNow(props.location)
		}
	}
	_getNow = (location) => {
		return location.pathname.split('/')[2]
	}

	shouldComponentUpdate(newProps) {
		let now = this._getNow(newProps.location);
		if (now != this.state.now) {
			this.setState({
				now
			})
			return false;
		}
		return true;
	}

	render() {
		let { now } = this.state;
		return (
			<Row className="wrap">
				<Col md={6} xs={24}>
					<Menu className="indexMenu" selectedKeys={[now]}>
						<Menu.Item key="all">
							<Link to="/index/all" >全部</Link>
						</Menu.Item>
						<Menu.Item key="good">
							<Link to="/index/good" >精华</Link>
						</Menu.Item>
						<Menu.Item key="ask">
							<Link to="/index/ask" >问答</Link>
						</Menu.Item>
						<Menu.Item key="share">
							<Link to="/index/share">分享</Link>
						</Menu.Item>
						<Menu.Item key="job">
							<Link to="/index/job" >招聘</Link>
						</Menu.Item>
						<Menu.Item key="dev">
							<Link to="/index/dev" >测试</Link>
						</Menu.Item>
					</Menu>
				</Col>
				<Col md={18} xs={24} className="indexBody">
					<IndexList />
				</Col>
			</Row>
		)
	}
}
export default withRouter(Index);